<template>
	<view>
		<baseForm :column.sync="column" @submitFun="submitFun" @changeColumn="changeColumn" :submitStatus="submitDisable"></baseForm>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import formMixins from '@/libs/formMixins.js';
import { format } from '@/libs/common.js';
export default {
	mixins: [formMixins],
	data() {
		return {
			column: [
				{
					label: '用餐日期',
					name: 'dinnerTime',
					type: 'picker',
					mode: 'date',
					required: true,
					disabled: false,
					value: format('YY-mm-dd', new Date()),
					text: format('YY-mm-dd', new Date())
				},
				{
					label: '被接待单位',
					name: 'entertainCustomers',
					type: 'normalInput',
					disabled: false,
					required: true,
					value: ''
				},
				{
					label: '用餐人数',
					name: 'dinnerNumbers',
					type: 'normalInput',
					inputType: 'number',
					disabled: false,
					required: true,
					value: ''
				},
				{
					label: '附件(最多上传三张)',
					type: 'upload',
					url: '/stu/common/uploadFile',
					docFileId: '',
					docFileUrl: '',
					attachmentVoListStr: '',
					limitSize: 3,
					disabled: false
				}
			],
		};
	},
	async onLoad() {
	},
	methods: {
		async submitFun() {
			let params = {
				dinnerTime: this.column[0].value.substring(0, 10),
				entertainCustomers: this.column[1].value,
				dinnerNumbers: this.column[2].value,
				attachmentVoListStr: this.column[3].attachmentVoListStr, //附件列表
			};
			let rules = [
				{
					key: 'entertainCustomers',
					checkFunc(value) {
						if (!value)	return false;
						return true;
					},
					errMsg: '请输入被接待单位'
				},
				{
					key: 'dinnerNumbers',
					checkFunc(value) {
						let reg = /^[1-9]\d*$/;
						return reg.test(value);
					},
					errMsg: '请输入正确的用餐人数'
				}
			]
			let checkRes = this.checkFormIsPassRules(params, rules);
			if (!checkRes.isPass) {
				uni.showToast({
					title: checkRes.errMsg,
					icon: 'none',
					duration: 2000,
				});
				return;
			}
			let resp = await this.$http.post({
				url: '/oa/wechat/dinnerApply/save',
				data: params
			});
			this.showToast('提交成功',()=> {uni.navigateBack()});
		},
	},
	components: {
		baseForm
	},
};
</script>

<style></style>
